// pointShop/dictInput/dictInput.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {
      label: {
        type: String,
        value: '名称'
      },
      list: {
        type: Array,
        value: [
          {
            id: Math.random(),
            title: '',
            itemList: [
              {
                id: Math.random(),
                label: '',
                value: ''
              }
            ]
          }
        ]
      }
    },

    /**
     * 组件的初始数据
     */
    data: {

    },

    /**
     * 组件的方法列表
     */
    methods: {
      addEnum(){
        this.data.list.push({
          id: Math.random(),
          title: '',
          itemList: [
            {
              id: Math.random(),
              label: '',
              value: ''
            }
          ]
        })
        this.update()
      },
      removeEnum(e){
     
        let index = e.currentTarget.dataset.enumIndex
      
        this.data.list.splice(index, 1)
        this.update()
      },
      addItem(e){
        let enumIndex = e.currentTarget.dataset.enumIndex
        this.data.list[enumIndex].itemList.push({
          id: Math.random(),
          label: '',
          value: ''
        })
        this.update()
      },
      removeItem(e){
        let enumIndex = e.currentTarget.dataset.enumIndex
        let index = e.currentTarget.dataset.index
        this.data.list[enumIndex].itemList.splice(index, 1)
        this.update()
      },
      titleInput(e){
        console.log(e)
        let index = e.currentTarget.dataset.index
        this.data.list[index].title = e.detail.value
        this.update()
      },
      labelInput(e){
        let enumIndex = e.currentTarget.dataset.enumIndex
        let index = e.currentTarget.dataset.index
        this.data.list[enumIndex].itemList[index].label = e.detail.value
        this.update()
      },
      valueInput(e){
        let enumIndex = e.currentTarget.dataset.enumIndex
        let index = e.currentTarget.dataset.index
        this.data.list[enumIndex].itemList[index].value = e.detail.value
        this.update()
      },

      update(){
        this.setData({
          list: this.data.list
        })
        this.triggerEvent('change', this.data.list)
      }
    }
})